//
//  ActivityListHandle.m
//  DoubanDemo1
//
//  Created by lanou3g on 15/11/23.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "ActivityListHandle.h"
#import "ActivityList.h"
#import "DataTool.h"


static ActivityListHandle *handle = nil;

@implementation ActivityListHandle

+ (ActivityListHandle *)shareInstence
{
    if (handle == nil) {
        handle = [[ActivityListHandle alloc]init];
    }
    return handle;
}
//解析数据源
- (void)getActivityListDataSourceWithGoBackBlock:(GoBackBlock)goBackBlock
{
    [DataTool requestDataWithURLStr:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php" HTTPMethod:nil withHttpBody:nil blockBlock:^(id object) {
        NSDictionary *sourceDic = (NSDictionary *)object;
        NSArray *array = [sourceDic valueForKey:@"events"];
        self.activityListArray = [NSMutableArray array];
        for (NSDictionary *dic in array) {
            ActivityList *activityList = [[ActivityList alloc]init];
            [activityList setValuesForKeysWithDictionary:dic];
            NSDictionary *dic1 = [dic valueForKey:@"owner"];
            self.nameStr = [dic1 valueForKey:@"name"];
            [activityList setValue:self.nameStr forKey:@"name"];
            [self.activityListArray addObject:activityList];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            goBackBlock();
        });
    }];
}



- (NSInteger)rowForActivityList
{
    return self.activityListArray.count;
}

- (ActivityList *)activityListForIndexPath:(NSIndexPath *)indexPath
{
    ActivityList *activityList = self.activityListArray[indexPath.row];
    //NSLog(@"shuzu%@",self.activityListArray[indexPath.row]);
    return activityList;
}



@end
